﻿using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DormMS.IService;
using DormMS.IService.Common;
using DormMS.Service;
using DormMS.Service.Common;

namespace WeChat.Quartz
{
    public class CommissionJob:IJob
    {
        private string appId;
        private string secret;
        private string domainUrl;
        private ILogService logService;
        //private IActivityTeamService activityTeamService;
        private IWxConfigService wxConfigService;
        private string checkUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={0}";//用来验证accessToken的地址
        public CommissionJob()
        {
            logService = new LogService();
            //activityTeamService = new ActivityTeamService();
            wxConfigService = new WxConfigService();
            var config = wxConfigService.GetConfig();
            appId = config.AppId;
            secret = config.AppSecret;
            //domainUrl = config.DomainName;
        }

        /// <summary>
        /// 定时任务逻辑
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                //var act = new Activity_RedCent();
                //var userList = activityTeamService.ChangeTeamStatus(out act);
                //if (act != null && userList.Count > 0)
                //{
                //    //string token = AccessTokenContainer.TryGetAccessToken(appId, secret);
                //    string token = wxConfigService.GetCurrentToken(checkUrl, appId, secret);
                //    var articles = new List<Article>();
                //    var article = new Article()
                //    {
                //        Description = "抱歉，本活动已经过期了，下次再接再厉吧！",
                //        PicUrl = domainUrl + act.ActivityCover,
                //        Title = act.ActivityName,
                //        Url = ConfigurationManager.AppSettings["DomainUrl"].ToString() + "/Activity/Index"
                //    };
                //    articles.Add(article);
                //    foreach (var item in userList)
                //    {
                //        if (!string.IsNullOrWhiteSpace(item.OpenId))
                //        {
                //            CustomApi.SendNews(token, item.OpenId, articles);
                //        }
                //    }
                //}
            }
            catch (Exception ex)
            {
                logService.SecurityLog(990, "ddd", "计划任务异常", "试试", ex.Message, "ssaga");
            }

        }
    }
}